package com.run.go.gearbox.mysql.codec;

import com.run.go.gearbox.mysql.request.ClientRequest;

import java.io.IOException;
import java.io.OutputStream;


public class MysqlEncoder implements Encoder {
    @Override
    public void encode(ClientRequest request, OutputStream out) throws IOException {
        int length = request.getLength();

        // Write the length of the packet
        out.write(length & 0xFF);
        out.write(length >> 8 & 0xFF);
        out.write(length >> 16 & 0xFF);


        // Write the packet number
        out.write(request.getPacketNumber());

        request.writeToOutputStream(out);

    }
}